﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Connect tho the database to get some info
using MySql.Data.MySqlClient;

namespace Läxomatic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public bool login(string username, string password)
        {
            Myskul mys = new Myskul("root", "123", "localhost", "johan_johan");

            Tabell Salt = new Tabell(mys.Command("select salt FROM user where loginname= '" + username + "';"));
            string checksum = Hash.getHashSha256(Salt.getFistElement() + username + password,17);
            Tabell userExist = new Tabell(mys.Command("select * FROM user where loginname= '" + username + "'AND checksum='" + checksum + "';"));
            if (!userExist.isEmpty())
                return true;
            else
                return false;
        }
        //button event to log in with the entered data in textboxes 
        private void btn_login_Click_1(object sender, EventArgs e)
        {
            if (login(txtuser.Text, txtpass.Text) == true)
            {
              
                LarareMainInterface Lärarform = new LarareMainInterface();
                Lärarform.Show();
                this.Hide();
            }
            else {
                felInfolbl.Visible = true;
            }
        }
    }

 }
